#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
class subscribe : public rclcpp::Node
{
    public:
    subscribe(std::string name) : Node(name)
    {
        RCLCPP_INFO(this->get_logger(),"I am %s",name.c_str());
        command_subscribe_ = this->create_subscription<std_msgs::msg::String>("command", 10, std::bind(&subscribe::command_callback, this, std::placeholders::_1));

    }
    private:
    rclcpp::Subscription<std_msgs::msg::String>::SharedPtr command_subscribe_;
    void command_callback(const std_msgs::msg::String::SharedPtr msg)
    {
        double speed = 0.1f;
        if(msg->data == "welcome to ros2")
        {
            speed = 0.2f;
        }
        RCLCPP_INFO(this->get_logger(),"recieve[%s],speed %f",msg->data.c_str(),speed);
    }
    
};
int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<subscribe>("topicsubscriber_01");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}